﻿// Inner Fire 游戏引擎库
// 渲染贴图
//
// Copyright (c) 2024 by 尔西大帝. All rights reserved.
//
// 这个类用于离屏渲染贴图的基类。比如阴影贴图，环境光遮蔽等等。
// 根据《DirectX12游戏开发实战》中的工具类修改。原作者：Frank Luna
//
// Author: 尔西大帝
// Email: 2670613871@qq.com
// Created: 2024-12-04

#include "render_texture.h"
#include <enum_parser.h>

namespace ifire::dx {

RenderTexture::RenderTexture(
    ID3D12Device* device, UINT width, UINT height, DXGI_FORMAT format) {
  device_ = device;
  width_ = width;
  height_ = height;
  format_ = format;

  viewport_ = {0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f};
  scissor_rect_ = {0, 0, (int)width, (int)height};
}

void RenderTexture::OnResize(UINT width, UINT height) {
  if ((width_ != width) || (height_ != height)) {
    width_ = width;
    height_ = height;

    BuildResource();

    // 因为资源已经更新了，所以视图也需要更新
    BuildDescriptors();
  }
}

DebugLayer ReadDebugLayer(ikit::sstr name) {
  static std::pair<ikit::sstr, DebugLayer> enums[] = {
      {"None", DebugLayer::None},     //
      {"Shadow", DebugLayer::Shadow}, //
      {"Ssao", DebugLayer::Ssao}      //
  };
  static ikit::EnumParser<DebugLayer> debugLayerParser(
      enums, (int)DebugLayer::Count);
  return debugLayerParser.Get(name, DebugLayer::None);
}

} // namespace ifire::dx